$(".cutometype").click(function(){
		ajaxlist("","cutometype");
		
})
$(".cutomecitytype").click(function(){
		ajaxlist("","cutomecitytype");
		
})
/**
 * 客户姓名/手机号搜索
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
function ajaxlist(page,datatype){
	var phreg  = /^1[3|4|5|6|7|8][0-9]{9}$/;
	// var phreg = /^1\d{10}$/;
	var username_reg = /^[\u4E00-\u9FA5A-Za-z]+$/;
	if(datatype == "cutometype"){
		var cutometel = $("input[name='cutometel']").val().trim();
		if(phreg.test(cutometel) || username_reg.test(cutometel)){
			data = {username:cutometel};
		}else{
			sweetAlert('','手机号或客户姓名不能为空','error');
        	return false;
		}
	}else if(datatype == "cutomecitytype"){
		var sheng = $("#sheng").val();
		var shi   = $("#shi").val();
		var kehu  = $("#kehu").val();
		// if(sheng || shi || kehu){
		data = {provinceid:sheng,cityid:shi,status:kehu};
	}
	if(!page){
        page=1;
    }
	ajax({
		'url':'/admin/Singlerate/CustomerList',
		'type':'post',
		'data':data,
		'dataType':'json',
		'success':function(response) {
			if(response.resdata && response.resdata.length != 0){
				setItem('orders', response.resdata);
	            var totalPage = Math.ceil(response.resdata.length / 15);
	            showPage(1, totalPage, addInfo);recovery();
	            addInfo(1, totalPage);
			}else{
				addNotify();
			}

		}
	},true)
}
/**
 * 客户信息查询
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
function addInfo(page,totalPage){
        	var response = pageData(page,totalPage)
			if (data.length <= 0) {
	            $('.table_hover tr').remove();
	            return;
	        }
	        $('.table_hover tr').remove();
	        showPage(page,totalPage,addInfo);
			var ii =0;
			var rs = $('#thover').children().length;
	        for(var i =0;i < rs;i++){
	            $("#trhtml").remove();
	        }
            typecheckbox(true);
			for(i in response){
				ii++
				dat = gethunying(response[i]);
				var bankflow = "";
				if (dat.bankflow_url == null ||  dat.bankflow_url == false) {
			        bankflow = "无";
			    }else{
			    	for (j1 in dat.bankflow_url) {
						var image = dat.bankflow_url[j1].substring(2);
						bankflow += "<a href=javascript:ejectmodel('"+image+"')>图"+j1+"</a>&nbsp;";
					}
			    }
			    
				var workproofurl = "";
				if(dat.workproof_url == null ||  dat.workproof_url == false){
				   workproofurl = "无";
				}else{
					for (j2 in dat.workproof_url) {
						var image = dat.workproof_url[j2].substring(2);
						workproofurl += "<a href=javascript:ejectmodel('"+image+"')>图"+j2+"</a>&nbsp;";
					}
				}
				var creditreporturl = "";
				if(dat.creditreport_url == null ||  dat.creditreport_url== false){
				    var creditreporturl  = "无";
				}else{
					for ( j3 in dat.creditreport_url) {
						var image = dat.creditreport_url[j3].substring(2);
						creditreporturl += "<a href=javascript:ejectmodel('"+image+"')>图"+j3+"</a>&nbsp;";
					}
				}
				
				var otherdataurl = "";
				if(dat.otherdata_url == null ||  dat.otherdata_url == false){
					otherdataurl = "无";
				}else{
					for ( j4 in dat.otherdata_url) {
						var image = dat.otherdata_url[j4].substring(2);
						otherdataurl += "<a href=javascript:ejectmodel('"+image+"')>图"+j4+"</a>&nbsp;";
					}
				}
				var driverurl = "";
				if(dat.driver_url == null ||  dat.driver_url == false){
				    data['driver_url'] = "无";
				}else{
					for ( j5 in dat.driver_url) {
						var image = dat.driver_url[j5].substring(2);
						driverurl += "<a href=javascript:ejectmodel('"+image+"')>驾驶证</a>&nbsp;";
					}
				}
				var identifyurl = "";
				if(dat.identify_url ==  null || dat.identify_url == false){
					identifyurl = "无";
				}else{
					for ( j6 in dat.identify_url) {
						var image = dat.identify_url[j6].substring(2);
						identifyurl += "<a href=javascript:ejectmodel('"+image+"')>身份证"+j6+"</a>&nbsp;";
					}
				}
				var html = '<tr id="trhtml">'+
				'<td>'+ii+'</td>'+
				'<td>'+dat.fullanme+'</td>'+
				'<td>'+dat.sex+'</td>'+
				'<td>'+dat.tel+'</td>'+
				'<td>'+dat.birthday+'</td>'+
				'<td>'+dat.marriage+'</td>'+
				'<td>'+dat.addssre+'</td>'+
				'<td>'+dat.liveaddress+'</td>'+
				'<td>'+dat.companyaddress+'</td>'+
				'<td>'+dat.housingnature+'</td>'+
				'<td>'+identifyurl+
				'<td>'+dat.identify+'</td>'+
				'<td>'+dat.bank+'</td>'+
				'<td>'+dat.banker+'</td>'+
				'<td>'+dat.usertype+'</td>'+
				'<td>'+driverurl+
				'<td>'+dat.workunit+'</td>'+
				'<td>'+dat.income+'</td>'+
				'<td>'+dat.creditcard+'</td>'+
				'<td>'+dat.borrowing+'</td>'+
				'<td>'+"无"+'</td>'+
				'<td>'+bankflow+'</td>'+
				'<td>'+workproofurl+'</td>'+
				'<td>'+creditreporturl+'</td>'+
				'<td>'+otherdataurl+'</td>'+
				'<td>'+dat.contacts_name+"/"+dat.contacts_bearing+"/"+dat.contacts_phone+'</td>'+
				'<td>'+dat.contacts_user_name+"/"+dat.contacts_sip_bearing+"/"+dat.contacts_phone_tel+'</td>'+
				'<td>'+dat.gwname+'</td>'+
				'<td>'+dat.gwusernum+'</td>'+
				'<td>'+dat.waynum+'</td>'+
				'<td>'+dat.provincename+'</td>'+
				'<td>'+dat.cityname+'</td>'+
				'<td>'+dat.thpaytype+'</td>'+
				'<td>'+dat.status+'</td>'+
				'<td>'+dat.orderid+'</td>'+
				'<td>'+dat.jdc_price+'</td>'+
				'<td>'+dat.thpay+'</td>'+
				// '<td>'+"<a href='javascript:;' >查看详情</a>"+'</td>'+
				'</tr>';
				$("#thover").append(html);
			}
			if (!filterTag) {
                tableHide();
            }else{
	            recovery();
	        }
}
function gethunying(data) {
	for(i in data){
		if(data[i] == null){
			data[i] = '无';
		}
	}
	if(data['contacts_name'] == null){
        data['contacts_name'] = "无";
    }
    if(data['contacts_bearing'] == null){
        data['contacts_bearing'] = "无";
    }
    if(data['contacts_phone'] == null){
        data['contacts_phone'] = "无";
    }
    if(data['contacts_user_name'] == null){
        data['contacts_user_name'] = "无";
    }
    if(data['contacts_sip_bearing'] == null){
        data['contacts_sip_bearing'] = "无";
    }
    if(data['contacts_phone_tel'] == null){
        data['contacts_phone_tel'] = "无";
    }

    if(data['income'] == "1"){
        data['income'] = "10001以上";
    }else if(data['income'] == "2"){
        data['income'] = "8001-10000";
    }else if(data['income'] == "3"){
        data['income'] = "5001-8000";
    }else if(data['income'] == "4"){
        data['income'] = "4001-5000";
    }else if(data['income'] == "5"){
        data['income'] = "4001-5000";
    }else if(data['income'] == "6"){
        data['income'] = "4001-5000";
    }else if(data['income'] == "7"){
        data['income'] = "1001-2000";
    }else if(data['income'] == "8"){
        data['income'] = "1000以下";
    }

    if(data['marriage'] == "1"){
        data['marriage'] = "已婚有子女";
    }else if(data['marriage'] == "2"){
        data['marriage'] = "已婚无子女";
    }else if(data['marriage'] == "3"){
        data['marriage'] = "未婚";
    }else if(data['marriage'] == "4"){
        data['marriage'] = "其他";
    }

    if(data['creditcard'] == "1"){
        data['creditcard'] = "3张以下";
    }else if(data['creditcard'] == "2"){
        data['creditcard'] = "3张以上";
    }

    if(data['borrowing'] == "1"){
        data['borrowing'] = "无借款";
    }else if(data['borrowing'] == "2"){
        data['borrowing'] = "有借款但已还清";
    }else if(data['borrowing'] == "3"){
        data['borrowing'] = "有借款未还清";
    }

    if(data['housingnature'] == "1"){
        data['housingnature'] = "自己有房";
    }else if(data['housingnature'] == "2"){
        data['housingnature'] = "房屋按揭";
    }else if(data['housingnature'] == "3"){
        data['housingnature'] = "租房住";
    }else if(data['housingnature'] == "4"){
        data['housingnature'] = "和父母同住";
    }
    if(data['usertype'] == "0"){
        data['usertype'] = "普通用户";
    }else if(data['usertype'] == "1"){
        data['usertype'] = "职员,";
    }else if(data['usertype'] == "2"){
        data['usertype'] = "副处级/公司副总/子公司总经理";
    }else if(data['usertype'] == "3"){
        data['usertype'] = "副科级/部门负责人/副经理/子公司副总";
    }
    if(data['status'] == "0"){
        data['status'] = "创建订单";
      }else if (data['status'] == "2") {
        data['status'] = "等待签约";
      }else if (data['status'] == "3") {
        data['status'] = "等待收款";
      }else if (data['status'] == "4") {
        data['status'] = "等待上牌";
      }else if (data['status'] == "5") {
        data['status'] = "等待提车";
      }else if (data['status'] == "6") {
        data['status'] = "已交付订单";
      }else if (data['status'] == "-1") {
        data['status'] = "拒单";
      }else if (data['status'] == "-2") {
        data['status'] = "订单驳回";
      }else if (data['status'] == "7") {
        data['status'] = "等待审核(风控经理)";
      }else if (data['status'] == "1") {
        data['status'] = "等待审核(城市经理)";	
      }
      
    return data;
}
/**
 * 显示图片
 * @param  {[type]} id [description]
 * @return {[type]}    [description]
 */
function ejectmodel(id){
    document.getElementById("imgmodeltanchu").src='http://jindouche-oss.oss-cn-beijing.aliyuncs.com/'+id;
    // document.getElementById("imgmodeltanchu").src='http://jindouche.oss-cn-beijing.aliyuncs.com'+id;
    $('.mask-layer').show();
}

/**
 * 客户导出数据
 */
$(".ExcelYear").click(function(){
	var list = $(this).val();
	if(!list){
		sweetAlert('','导出程序错误','error');
	    return false;
	}
    // console.log(arrarray);
	ajax({
		'url':'/admin/Singlerate/ExportExcelYear',
		'type':'post',
		'data':{status:list,arrarray:filterIndexs},
		'dataType':'json',
		'success':function(response) {
			if(response.success == "OK"){
                location.href = response.path;

			}
		}
	},true);
	
})

function typecheckbox(datatype){
    if(datatype){
        var lbox = "";
        for(i=0;i<=37;i++){
            if(i ==37){
                lbox+='<th calss="btn_rate selected" id="btn_filter">'+
                      '<button type="button" class="btn btn-warning btn_filter" >过滤</button>'+
                      '</th>'+
                      '<th calss="btn_rate selected" id="btn_recovery">'+
                      '<button type="button" class="btn btn_recovery" >重置</button>'+
                      '</th>';
            }else{
                lbox+="<th><input type='checkbox' class='checkbox_input'></th>";
            }
        }
        $(".tr_checkbox").html(lbox); 
    }
}

